class ModeController {

    def save = {
        DBConnection.commitTransaction(session.mode)
        flash.message=Inter.printOut('Changes Saved',session.language)
        session.modified = false// no need for showing popup window
        if(params.idProject.equals("null")){
            redirect(controller:params.currentController,action:params.currentView)
        }
        else{
            redirect(controller:params.currentController,action:params.currentView, id:params.idProject)
        }
    }

    def rollback = {
        DBConnection.rollbackTransaction(session.mode)
        flash.message=Inter.printOut('Changes Cancelled',session.language)
        session.modified = false// no need for showing popup window
        if(params.idProject.equals("null")){
            redirect(controller:params.currentController,action:params.currentView)
        }
        else{
            redirect(controller:params.currentController,action:params.currentView, id:params.idProject)
        }
    }

    def changeMode = {
        //System.out.println("-"+session.mode+"-")
        Date d = new Date()
        if((session.mode==null)||(!session.mode.equalsIgnoreCase("budget"))){
              session.mode="budget"
              DBConnection.rollbackTransaction(session.mode)
        }
        else{
            session.mode="sandbox"
            DBConnection.connect()
            DBConnection.startTransaction()

        }
        //System.out.println("-"+session.mode+"-")

        flash.message = Inter.printOut('Mode Changed',session.language)
        if(params.idProject.equals("null")){
            redirect(controller:params.currentController,action:params.currentView)
        }
        else{
            redirect(controller:params.currentController,action:params.currentView, id:params.idProject)
        }
    }
}
